import logging

from fastapi import APIRouter, Depends

from forward.api.admin.schemas.setting import (
    SettingWebsiteInSchema,
    SettingCopyrightInSchema,
    SettingProtocolInSchema,
    SettingStorageDetailInSchema,
    SettingStorageEditInSchema,
    SettingStorageChangeInSchema,
    SettingDictTypeOutSchema,
    SettingDictTypeListInSchema,
    SettingDictTypeAddInSchema,
    SettingDictTypeEditInSchema,
    SettingDictTypeDeleteInSchema,
    SettingDictTypeDetailInSchema,
    SettingDictDataListInSchema,
    SettingDictDataDetailInSchema,
    SettingDictDataAddInSchema,
    SettingDictDataEditInSchema,
    SettingDictDataDeletelInSchema,
    SettingDictDataOutSchema,
    SettingHotSearchInSchema,
    SettingLoginInSchema,
    SettingUserInSchema,
    SettingSmsDetailInSchema,
    SettingSmsSaveInSchema,
    SettingNoticeListInSchema,
    SettingNoticeDetailInSchema,
    SettingNoticeSaveInSchema,
)
from forward.api.admin.service.setting.copyright import SettingCopyrightService
from forward.api.admin.service.setting.dict_manager import (
    SettingDictTypeService,
    SettingDictDataService,
)
from forward.api.admin.service.setting.login import SettingLoginService
from forward.api.admin.service.setting.notice import SettingNoticeService
from forward.api.admin.service.setting.protocol import SettingProtocolService
from forward.api.admin.service.setting.search import SettingSearchService
from forward.api.admin.service.setting.sms import SettingSmsService
from forward.api.admin.service.setting.storage_service import SettingStorageService
from forward.api.admin.service.setting.user import SettingUserService
from forward.api.admin.service.setting.website import SettingWebsiteService
from forward.http_base import unified_resp
from forward.schema_base import PageInationResult

logger = logging.getLogger(__name__)
router = APIRouter(prefix="/setting")


@router.get("/website/detail")
@unified_resp
async def website_detail(
    website_service: SettingWebsiteService = Depends(SettingWebsiteService.instance),
):
    """获取网站配置信息"""
    return await website_service.detail()


@router.post("/website/save")
@unified_resp
async def website_save(
    website_in: SettingWebsiteInSchema,
    website_service: SettingWebsiteService = Depends(SettingWebsiteService.instance),
):
    """保存网站配置信息"""
    return await website_service.save(website_in)


@router.get("/copyright/detail")
@unified_resp
async def copyright_detail(
    copyright_service: SettingCopyrightService = Depends(
        SettingCopyrightService.instance
    ),
):
    """获取网站备案信息"""
    return await copyright_service.detail()


@router.post("/copyright/save")
@unified_resp
async def copyright_save(
    copyright_in: SettingCopyrightInSchema,
    copyright_service: SettingCopyrightService = Depends(
        SettingCopyrightService.instance
    ),
):
    """保存网站备案信息"""
    return await copyright_service.save(copyright_in)


@router.get("/protocol/detail")
@unified_resp
async def protocol_detail(
    protocol_service: SettingProtocolService = Depends(SettingProtocolService.instance),
):
    """获取网站政策信息"""
    return await protocol_service.detail()


@router.post("/protocol/save")
@unified_resp
async def protocol_save(
    protocol_in: SettingProtocolInSchema,
    protocol_service: SettingProtocolService = Depends(SettingProtocolService.instance),
):
    """保存网站政策信息"""
    return await protocol_service.save(protocol_in)


@router.get("/storage/list")
@unified_resp
async def storage_list(
    service: SettingStorageService = Depends(SettingStorageService.instance),
):
    return await service.list()


@router.get("/storage/detail")
@unified_resp
async def storage_detail(
    storage_detail_in: SettingStorageDetailInSchema = Depends(),
    service: SettingStorageService = Depends(SettingStorageService.instance),
):
    return await service.detail(storage_detail_in.alias)


@router.post("/storage/edit")
@unified_resp
async def storage_edit(
    storage_edit_in: SettingStorageEditInSchema,
    service: SettingStorageService = Depends(SettingStorageService.instance),
):
    return await service.edit(storage_edit_in)


@router.post("/storage/change")
@unified_resp
async def storage_change(
    storage_change_in: SettingStorageChangeInSchema,
    service: SettingStorageService = Depends(SettingStorageService.instance),
):
    return await service.change(storage_change_in.alias, storage_change_in.status)


@router.get("/dict/type/all")
@unified_resp
async def dict_type_all(
    service: SettingDictTypeService = Depends(SettingDictTypeService.instance),
):
    return await service.all()


@router.get(
    "/dict/type/list", response_model=PageInationResult[SettingDictTypeOutSchema]
)
@unified_resp
async def dict_type_list(
    list_in: SettingDictTypeListInSchema = Depends(),
    service: SettingDictTypeService = Depends(SettingDictTypeService.instance),
):
    return await service.list(list_in)


@router.get("/dict/type/detail")
@unified_resp
async def dict_type_detail(
    detail_in: SettingDictTypeDetailInSchema = Depends(),
    service: SettingDictTypeService = Depends(SettingDictTypeService.instance),
):
    return await service.detail(detail_in)


@router.post("/dict/type/add")
@unified_resp
async def dict_type_add(
    add_in: SettingDictTypeAddInSchema,
    service: SettingDictTypeService = Depends(SettingDictTypeService.instance),
):
    return await service.add(add_in)


@router.post("/dict/type/edit")
@unified_resp
async def dict_type_edit(
    edit_in: SettingDictTypeEditInSchema,
    service: SettingDictTypeService = Depends(SettingDictTypeService.instance),
):
    return await service.edit(edit_in)


@router.post("/dict/type/del")
@unified_resp
async def dict_type_del(
    delete_in: SettingDictTypeDeleteInSchema,
    service: SettingDictTypeService = Depends(SettingDictTypeService.instance),
):
    return await service.delete(delete_in)


@router.get("/dict/data/all")
@unified_resp
async def dict_data_all(
    all_in: SettingDictDataListInSchema = Depends(),
    service: SettingDictDataService = Depends(SettingDictDataService.instance),
):
    return await service.all(all_in)


@router.get(
    "/dict/data/list", response_model=PageInationResult[SettingDictDataOutSchema]
)
@unified_resp
async def dict_data_list(
    list_in: SettingDictDataListInSchema = Depends(),
    service: SettingDictDataService = Depends(SettingDictDataService.instance),
):
    return await service.list(list_in)


@router.get("/dict/data/detail")
@unified_resp
async def dict_data_detail(
    detail_in: SettingDictDataDetailInSchema = Depends(),
    service: SettingDictDataService = Depends(SettingDictDataService.instance),
):
    return await service.detail(detail_in)


@router.post("/dict/data/add")
@unified_resp
async def dict_data_add(
    add_in: SettingDictDataAddInSchema,
    service: SettingDictDataService = Depends(SettingDictDataService.instance),
):
    return await service.add(add_in)


@router.post("/dict/data/edit")
@unified_resp
async def dict_data_edit(
    edit_in: SettingDictDataEditInSchema,
    service: SettingDictDataService = Depends(SettingDictDataService.instance),
):
    return await service.edit(edit_in)


@router.post("/dict/data/del")
@unified_resp
async def dict_data_del(
    delete_in: SettingDictDataDeletelInSchema,
    service: SettingDictDataService = Depends(SettingDictDataService.instance),
):
    return await service.delete(delete_in)


@router.get("/search/detail")
@unified_resp
async def search_detail(
    search_service: SettingSearchService = Depends(SettingSearchService.instance),
):
    """热门搜索详情"""
    return await search_service.detail()


@router.post("/search/save")
@unified_resp
async def search_save(
    hot_search_in: SettingHotSearchInSchema,
    search_service: SettingSearchService = Depends(SettingSearchService.instance),
):
    """热门搜索保存"""
    return await search_service.save(hot_search_in)


@router.get("/login/detail")
@unified_resp
async def login_detail(
    login_service: SettingLoginService = Depends(SettingLoginService.instance),
):
    """登录设置详情"""
    return await login_service.detail()


@router.post("/login/save")
@unified_resp
async def login_save(
    login_in: SettingLoginInSchema,
    login_service: SettingLoginService = Depends(SettingLoginService.instance),
):
    """登录设置保存"""
    return await login_service.save(login_in)


@router.get("/user/detail")
@unified_resp
async def user_detail(
    user_service: SettingUserService = Depends(SettingUserService.instance),
):
    """用户设置详情"""
    return await user_service.detail()


@router.post("/user/save")
@unified_resp
async def user_save(
    user_in: SettingUserInSchema,
    user_service: SettingUserService = Depends(SettingUserService.instance),
):
    """用户设置保存"""
    return await user_service.save(user_in)


@router.get("/sms/list")
@unified_resp
async def sms_list(
    sms_service: SettingSmsService = Depends(SettingSmsService.instance),
):
    """短信引擎列表"""
    return await sms_service.list()


@router.get("/sms/detail")
@unified_resp
async def sms_detail(
    detail_in: SettingSmsDetailInSchema = Depends(),
    sms_service: SettingSmsService = Depends(SettingSmsService.instance),
):
    """短信引擎详情"""
    return await sms_service.detail(detail_in.alias)


@router.post("/sms/save")
@unified_resp
async def sms_save(
    save_in: SettingSmsSaveInSchema,
    sms_service: SettingSmsService = Depends(SettingSmsService.instance),
):
    """短信引擎保存"""
    return await sms_service.save(save_in)


@router.get("/notice/list")
@unified_resp
async def notice_list(
    list_in: SettingNoticeListInSchema = Depends(),
    notice_service: SettingNoticeService = Depends(SettingNoticeService.instance),
):
    """通知设置列表"""
    return await notice_service.list(list_in.recipient)


@router.get("/notice/detail")
@unified_resp
async def notice_detail(
    detail_in: SettingNoticeDetailInSchema = Depends(),
    notice_service: SettingNoticeService = Depends(SettingNoticeService.instance),
):
    """通知设置详情"""
    return await notice_service.detail(detail_in.id)


@router.post("/notice/save")
@unified_resp
async def notice_save(
    save_in: SettingNoticeSaveInSchema,
    notice_service: SettingNoticeService = Depends(SettingNoticeService.instance),
):
    """通知设置保存"""
    return await notice_service.save(save_in)
